<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-6-3
 * Func   银行卡
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$table = Table('user_bank');
$utable = Table('user');
	
if($a == 'add'){
	
}
else if($a == 'del')
{
    $id = trim($_GET['id']);
    if($id)
    {
        $id = explode(',',$id);
        foreach($id as $key => $val)
        {
			$id[$key] = intval($val);
        }
		
        $flag = $_GET['flag'] ? 1 : 0;
        $db->exec('UPDATE '.$table.' SET status = '.$flag.' WHERE id IN ('.implode(',',$id).')');
    }
	
	//ShowMsg('操作成功','?m='.$m.'&c='.$c);
	AjaxReturn(0,'操作成功');
}
else
{
	$statuss = ['不启用','启用'];
	
	$data  = array();
	$where = ' FROM '.$table.' t LEFT JOIN '.$utable.' u ON t.uid = u.id WHERE 1 ';
    
	$uid = intval($_GET['uid']);
	$uid && $where .= ' AND t.uid = '.$uid;
	
    $status = intval($_GET['status']);
	$status && $where .= ' AND t.status = '.($status > 0 ? $status : 0);
    
	$title = NoBadStr($_GET['title']);
	$title && $where .= ' AND (t.bankcard LIKE \'%'.$title.'%\' OR u.username LIKE \''.$title.'\') ';

	$tmp = $db->getrow('SELECT COUNT(1) AS p '.$where);
	if($tmp['p'])
	{
		$page = max(1,intval($_GET['page']));
		$size = 20;
		$limit = $_GET['export'] ? '' : ' LIMIT '.($page - 1) * $size.','.$size;
		
		$url = '?m='.$m.'&c='.$c.'&a='.$a.'&title='.$title.'&status='.$status.'&uid='.$uid;
		
		$data = $db->getall('SELECT t.*,u.username '.$where.' ORDER BY t.id DESC '.$limit);
		
		// 获取银行设置信息
		$bankList      = $db->getall('SELECT * FROM ' . Table('web_bank'));
		$bankListIdKey = array();
		foreach ($bankList as $k => $v){
		    $bankListIdKey[$v['id']] = $v;
		}
		
		$multi = Multi($url,$page,$tmp['p'],$size);
	}
	
	//	导出
	if($_GET['export'])
	{
		header("Content-type:application/vnd.ms-excel");
        header("Content-Disposition:filename=".'会员列表'.date("YmdHis").".xls"); //“生成文件名称”=自定义
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');

		echo "上级\t账户\t昵称\t会员类型\t余额\t返点\t注册日期\t注册IP\t最后登陆IP\t下级人数\t状态\t推广码\t\n";
        foreach ($data as $key => $val)
        {
			echo $upuids[$val['upuid']]['username'],"\t";
			echo $val['username'],"\t";
			echo $val['nickname'],"\t";
			echo $gids[$val['gid']],"\t";
			echo $val['money'],"\t";
			echo $val['rebate'],"%\t";
			echo date('Y/m/d H:i',$val['reg_time']),"\t";
			echo $val['reg_ip'],"\t";
			echo $val['last_ip'],"\t";
			echo $val['sons'],"\t";
			echo $statuss[$val['status']],"\t";
			echo $val['id'],"\t";"\t\n";
        }
		exit;
	}
	
	$tpl->display('user/bank');
}